import request from '../../utils/request'
// pages/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperPicture: [],
    categoryList: [],
    hotGoodsList: []
  },

  /**
   * 点击搜索框
   */
  inputBind() {
    wx.navigateTo({
      url: '/goodsPackage/pages/search/search'
    })
  },

  /**
   * 去商品详情页
   */
  toGoods(options) {
    let id = options.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/goodsPackage/pages/goods/goods?goodsId=' + id,
    })
  },

  /**
   * 去分类页
   */
  toCategory(options) {
    if (options.currentTarget.dataset.id != undefined) {
      let id = options.currentTarget.dataset.id;
      wx.reLaunch({
        url: '/pages/category/category?id=' + id,
      })
    } else {
      wx.reLaunch({
        url: '/pages/category/category',
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function(options) {
    let keys = new Array("SWIPER_IMAGE");
    let swiperPictureResult = await request("/config/list", {
      keys
    }, 'post');
    let categoryListResult = await request('/category/indexList');
    let hotGoodsListResult = await request('/goods/indexList');
    this.setData({
      categoryList: categoryListResult.data,
      hotGoodsList: hotGoodsListResult.data,
      swiperPicture: swiperPictureResult.data
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})